
import 'dart:typed_data';


import 'dart:convert';

import 'package:eciesdart/eciesdart.dart';
import 'package:xim/common/util/ecies.dart' as Ecies;
import 'package:xim/common/util/secp256.dart';

void main(){

  // var mnemonic = Secp256R1Util.generateMnemonic();
  // var seed = Secp256R1Util.mnemonicToSeed(mnemonic);
  // print("seed:$seed");
  var seed = [115, 8, 36, 230, 145, 92, 226, 22, 47, 140, 144, 237, 119, 117, 70, 67, 76, 0, 184, 215, 194, 41, 67, 49, 171, 65, 52, 74, 155, 36, 30, 126, 223, 229, 116, 5, 32, 76, 37, 202, 46, 68, 145, 47, 216, 115, 86, 66, 240, 135, 225, 182, 26, 197, 85, 216, 143, 85, 150, 59, 198, 185, 24, 158];
  var privateKey = Secp256R1Util.generateEcPrivateKey(Uint8List.fromList(seed));
  var publicKey = Secp256R1Util.generateEcPublicKey(privateKey);

  var pub = publicKey.getEncoded();
  var pri = privateKey.getEncoded();
  print("pub(${publicKey.hexKey().length}):${publicKey.hexKey()}");
  print("pri:${privateKey.hexKey()}");

  const message = "Welcome to ECIES";
  var messageBytes = utf8.encode(message);
  // final cipherText = Ecies.encryptByR1(pub, messageBytes);
  // print("cipherText:$cipherText");
  // print("cipherText:${base64.encode(cipherText)}");
  // final decryptedBytes = Ecies.decryptByR1(pri, cipherText);
  // final decryptedMessage = utf8.decode(decryptedBytes);
  // print(decryptedMessage);

  for(var i=0;i<10;i++){
    final cipherText = Ecies.encryptByR1(pub, messageBytes);
    print(cipherText);
  }

  // var a = "BJ55nf9PZEUdAWv1k5Gay/kd/ZLNJwjqRK5z8/lHIVBUfa8QaE8KSu7i9cYfJiX7NHPd1CjTQnvTbdrlJp12t88H9R0qIpL84eNVGDHrDcs/RjUe04xX/QbCY9I4KxwoJAFeVEM=";
  // var decode = base64.decode(a);
  // final res = Ecies.decryptByR1(pri, decode);
  // final text = utf8.decode(res);
  // print(text);
  // sage
  // https://blog.csdn.net/Fred_Bohr_Locke/article/details/123912812


  // MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEY4MGnVPveHC4KdXG2UbvQDE2SQEZL62f
  // vRVpinGP1adkve+OvvWu09yj+OdKdSq+ZG5bHfrZqF4OS94h/cOyPw==

  String ax = "MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEY4MGnVPveHC4KdXG2UbvQDE2SQEZL62fvRVpinGP1adkve+OvvWu09yj+OdKdSq+ZG5bHfrZqF4OS94h/cOyPw==";

  var c = base64.decode(ax);
  var mx = bytesToBigInt(c);
  print(mx.toRadixString(16));

}